﻿#ifndef ELEMENTTREEMODEL_H
#define ELEMENTTREEMODEL_H

#include "ElementtreeItem.h"
#include <QAbstractItemModel>
#include <QStyledItemDelegate>

class ElementTreeItem;
class QPainter;
class ElementTreeModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    class TreeModeReader
    {
    public:
        TreeModeReader(){}
        virtual ~TreeModeReader(){}
        virtual ElementTreeItem* read(const QString& filePath) const=0 ;
        ElementTreeItem* read(QString&& filePath){
            return read(filePath);
        }
    };
public:
    explicit ElementTreeModel(QObject *parent = nullptr);
    ~ElementTreeModel();
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
    bool readElementsFile(const TreeModeReader* reader,const QString& fileName);
    Q_INVOKABLE int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    Q_INVOKABLE QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const  override;
    Q_INVOKABLE QModelIndex parent(const QModelIndex &index) const  override;
private:
    void setRoot(ElementTreeItem *root){rootItem=root;}
    ElementTreeItem *rootItem;
};

#endif // ELEMENTTREEMODEL_H
